package com.willian.andrappfw.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.ScrollView;

public class WScrollView extends ScrollView {
    private float mDownPosX;
    private float mDownPosY;
    private final int iTouchSlop;

    public WScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.iTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public WScrollView(Context context) {
        super(context);
        this.iTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public boolean onInterceptTouchEvent(MotionEvent ev) {
        float x = ev.getX();
        float y = ev.getY();
        int action = ev.getAction();
        switch(action) {
            case 0:
                this.mDownPosX = x;
                this.mDownPosY = y;
                break;
            case 2:
                float deltaX = Math.abs(x - this.mDownPosX);
                float deltaY = Math.abs(y - this.mDownPosY);
                if (deltaX > deltaY && deltaX > (float)this.iTouchSlop) {
                    return false;
                }
        }

        return super.onInterceptTouchEvent(ev);
    }
}
